public class RepeatedStringMatch {

    public static void main(String[] args) {
        String s = "abcabc";
        System.out.println(s.indexOf("wxyz"));
    }

    public int repeatedStringMatch1(String a, String b) {
        int m = a.length();
        int n = b.length();
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < n / m; i++) {
            stringBuilder.append(a);
        }
        if (stringBuilder.toString().equals(b)) return n / m;
        stringBuilder.append(a);
        if (stringBuilder.toString().indexOf(b) != -1) return n / m + 1;
        stringBuilder.append(a);
        return stringBuilder.toString().indexOf(b) == -1 ? -1 : n / m + 2;
    }

    public int repeatedStringMatch(String a, String b) {
        int max = 2 * a.length() + b.length();
        int m = a.length();
        int n = b.length();
        StringBuilder stringBuilder = new StringBuilder();
        int ans = 0;
        for (int i = 0; i < n / m - 1; i++) {
            stringBuilder.append(a);
        }
        while (stringBuilder.length() < max) {
            stringBuilder.append(a);
            ans++;
            if (stringBuilder.indexOf(b) != -1) return ans;
        }
        return -1;
    }
}
